home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 3_0 / RAMSTART / RS(DLOG).C < prev    next >
Text File  |  1987-03-28  |  20KB  |  794 lines

  1. /*
  2. RS(Dlog).c
  3.  
  4. P/O RamStart.c
  5. */
  6.  
  7. #include <MacTypes.h>
  8. #include <DialogMgr.h>
  9. #include <ControlMgr.h>
  10. #include <MemoryMgr.h>
  11. #include <ResourceMgr.h>
  12. #include <FileMgr.h>
  13. #include <ToolboxUtil.h>
  14. #include <EventMgr.h>
  15. #include <SegmentLdr.h>
  16. #include <SetJmp.h>
  17.  
  18. #include "RS.h"
  19.  
  20.  
  21. extern jmp_buf    env;
  22.  
  23. /* //  */
  24. /* Defined here */
  25.  
  26. static DialogPtr    ctlW;                        /* Used by MakeCtlW(), ShowFileName(), */
  27.                                                 /*   TestDLOG(), and GetNewSize(). */
  28.  
  29. static long            maxDisk;                    /* Set by MakeCtlW(); used also in GetNewSize(). */
  30.  
  31.  
  32. pascal void            Outline();
  33. pascal Boolean        DialogFilter();
  34. NoRamDisk();
  35. RestartUs();
  36.  
  37. /* //  */
  38. /* Display the control panel.  Much must be done to set it up.  The
  39. controls must be set and the window displayed; the Update mechanism is
  40. used to avoid redundant drawing.  Then the "copying" message is moved to
  41. a visible location. */
  42.  
  43. MakeCtlW( size )
  44. long            size;                            /* --> */
  45. {
  46.     short        type;
  47.     Handle        item;
  48.     Rect        box;
  49.     char        sizePstr[32];
  50.     extern        RamInfo ramInfo;
  51.     short        dirSize;
  52.     Handle        ramDirSize;
  53.  
  54.     
  55.     if( ctlW )                                    /* In case Main calls us twice. */
  56.         return;
  57.     
  58.     
  59.     ctlW = GetNewDialog( dlogCtl, NULL, -1 );
  60.  
  61.     GetDItem( ctlW, ctlISet, &type, &item, &box );    /* disable the Set button but leave it reporting hits */
  62.     HiliteControl( item, 255 );
  63.     
  64.     GetDItem( ctlW, dlogIScroll, &type, &item, &box );    /* Set up the control. */
  65.     SetCtlMin( item, MinDisk/1024 );
  66.     maxDisk = (ramInfo.oldBufPtr - (Ptr)GetZone() - MinHeap) / 1024;    /* Leaves room for application. */
  67.     SetCtlMax( item, maxDisk );
  68.     SetCtlValue( item, size /= 1024 );
  69.     
  70.     GetDItem( ctlW, ctlIEdit, &type, &item, &box );    /* Set the editText field. */
  71.     NumToString( size, sizePstr );
  72.     SetIText( item, sizePstr );
  73.     
  74.     GetDItem( ctlW, ctlIOutline, &type, &item, &box );    /* set the Outline user item code */
  75.     SetDItem( ctlW, ctlIOutline, type, Outline, &box );
  76.     
  77.     GetDItem( ctlW, ctlIBigDir, &type, &item, &box );
  78.     dirSize = 0;
  79.     ramDirSize = GetResource( 'RAMD', 257 );
  80.     if( ramDirSize )
  81.         dirSize = *(long *)*ramDirSize > 1;
  82.     SetCtlValue( item, dirSize );
  83.     
  84.     myHideDItem( ctlW, ctlIFile );
  85.     myHideDItem( ctlW, ctlIOpenMsg );
  86.     myHideDItem( ctlW, ctlICopyMsg );
  87.     
  88.     
  89.     ShowWindow( ctlW );
  90.     BeginUpdate( ctlW );                        /* Normally done via Update event. */
  91.     DrawDialog( ctlW );
  92.     EndUpdate( ctlW );
  93.     
  94.     myShowDItem( ctlW, ctlIFile );                /* show "Copying" message */
  95.     
  96.     InitCursor();
  97. }
  98.  
  99. /* //  */
  100. /* If a RAM disk is already installed, ask the user what to do about it.
  101. In the event that the current System file is on the RAM disk, don't let
  102. the user remove the RAM disk.
  103.  
  104. This would be just an alert if we didn't have to gray the buttons. */
  105.  
  106. short DoAlready( dqp )
  107. DrvQElPtr        dqp;
  108. {
  109.     DialogPtr    already;
  110.     short        sysDrvNum;
  111.     Handle        dh;
  112.     short        id;
  113.     long        rType;
  114.     Str255        rName;
  115.     short        type;
  116.     Handle        item;
  117.     Rect        box;
  118.     short        itemHit;
  119.     
  120.     
  121.     already = GetNewDialog( dlogAlready, NULL, -1 );
  122.     
  123.     GetDItem( already, alreadyIOutline, &type, &item, &box );
  124.     SetDItem( already, alreadyIOutline, type, Outline, &box );
  125.     
  126.     
  127.     /* Is the System file on the RAM disk?  From the FCB for the System file,
  128.        go to the VCB and get the vcbDrvNum. */
  129.     
  130.     sysDrvNum = *(short *)&( *(char **)&(FCBSPtr)[SysMap+20] )[72];
  131.     
  132.     if( sysDrvNum == dqp->dQDrive ) {            /* Don't let them remove the RAM disk if it has... */
  133.         GrayBtn( already, alreadyIRemove );        /* ...the active System file */
  134.         GrayBtn( already, alreadyINew );
  135.     }
  136.     else {                                        /* slide "boot disk" message off the window */
  137.         GetDItem( already, alreadyIBoot, &type, &item, &box );
  138.         OffsetRect( &box, 1000, 0 );
  139.         SetDItem( already, alreadyIBoot, type, item, &box );
  140.     }
  141.     
  142.     
  143.     SysBeep( 6 );
  144.     ShowWindow( already );
  145.     InitCursor();
  146.     ModalDialog( NULL, &itemHit );
  147.     DisposeWindow( already );
  148.     
  149.     return( itemHit );
  150. }
  151.  
  152. /* //  */
  153. /* Show in the ctlW which file we're opening or copying. */
  154.  
  155. ShowFileName( name, dItem )
  156. Ptr                name;                            /* --> */
  157. short            dItem;                            /* --> */
  158. {
  159.     short        type;
  160.     Handle        item;
  161.     Rect        box;
  162.     char    text[MAXLINE];
  163.     
  164.     
  165.     ParamText( name, NULL, NULL, NULL );        /* Also used by CopyFolder(). */
  166.     
  167.     GetDItem( ctlW, dItem, &type, &item, &box );    /* get the message */
  168.     GetIText( item, text );
  169.     GetDItem( ctlW, ctlIFile, &type, &item, &box );    /* draw the message */
  170.     SetIText( item, text );
  171.     
  172. #if 0
  173.     SetPort( ctlW );
  174.     
  175.     BeginUpdate( ctlW );                        /* Normally done via Update event. */
  176.     DrawDialog( ctlW );
  177.     EndUpdate( ctlW );
  178. #endif
  179. }
  180.  
  181. /* //  */
  182. /* Check if the user clicked in the controls box.  This normally would be
  183. handled in a main event loop, but this program doesn't have one.  The
  184. program is more like a single command that would have highlited the menu
  185. bar.
  186.  
  187. We respond as if in a modal dialog.  In fact, ModalDialog will eventually
  188. be called if any control was pressed, with the event that caused its
  189. activation; thus, pressing in a button will hilite it, instead of having to
  190. press twice.  The only difficulty is in getting rid of the other events
  191. that don't cause us to call ModalDialog.
  192.  
  193. Initially, the default button is Help, but once the user starts to change
  194. the size of the disk, the Set button is the default.  Thus, the user can
  195. type a new size and then press Return.  The Set button is item 1, but is
  196. initially inactive.  The Help button is outlined, so we respond to Return
  197. or Enter as if the Help button had been pressed.
  198.  
  199. This is called from inside the file copying routines, which open lots of
  200. files and create a couple of large heap structures.  Rather than call
  201. GetNewSize() directly, we give other routines a chance to clean up (and get
  202. off the stack) by signalling the need to get the size.
  203. */
  204.  
  205. TestDLOG()
  206. {
  207.     EventRecord    theEvent;
  208.     GrafPtr        oldPort;
  209.     Point        thePoint;
  210.     long        i;
  211.     short        type;
  212.     Handle        item;
  213.     Rect        box;
  214.     
  215. /* //  */
  216.     while( EventAvail( everyEvent, &theEvent ) ) {
  217.         if( theEvent.what == updateEvt ) {        /* Usually caused by Help window disappearing. */
  218.             BeginUpdate( theEvent.message );    /*   Note that the update event goes away now, */
  219.             DrawDialog( theEvent.message );        /*   so don't call GetNextEvent on this one. */
  220.             EndUpdate( theEvent.message );
  221.             continue;                            /* the update event is cleared so don't get it below */
  222.         }
  223.         
  224.         else if( IsDialogEvent(&theEvent) ) {
  225.             if( theEvent.what == keyDown ) {
  226.                 if(    (theEvent.message & charCodeMask) == '\r'/* Return == Help button. */
  227.                     || (theEvent.message & charCodeMask) == '\3' )
  228.                 {
  229.                     GetNextEvent( keyDownMask, &theEvent );    /* Used this event. */
  230.                     DoHelp();
  231.                     continue;
  232.                 }
  233.                 else longjmp( env, 'SZ' );    /* Never returns.  GetNewSize() gets current event. */
  234.             }
  235.             
  236.             
  237.             else if( theEvent.what == mouseDown ) {
  238.                 GetPort( &oldPort );
  239.                 SetPort( ctlW );            /* Safe 'cause its our only dialog. */
  240.                 
  241.                 thePoint = theEvent.where;
  242.                 GlobalToLocal( &thePoint );
  243.                 
  244.                 /* If the mouse was pressed in one of our controlling objects, do it.
  245.                 The Help button doesn't cause the program to restart. */
  246.                 
  247.                 for( i = ctlISet;  i <= ctlIBigDir;  ++i ) {
  248.                     GetDItem( ctlW, i, &type, &item, &box );
  249.                     if( PtInRect(thePoint, &box) ) {
  250.                         if( i == ctlIHelp )
  251.                             break;
  252.             
  253.                         if( i == ctlISet )    /* If Set button, drop this click so the user can... */
  254.                             GetNextEvent( mDownMask, &theEvent );    /* ...still set the size. */
  255.             
  256.                         longjmp( env, 'SZ' );    /* Never returns.  GetNewSize() gets current event. */
  257.                     }
  258.                 }
  259.                 
  260.                 GetNextEvent( mDownMask, &theEvent );    /* Used this event.  Get it now so TrackControl() */
  261.                                                         /*   isn't confused. */
  262.                 
  263.                 if( i == ctlIHelp  &&  TrackControl(item, thePoint, NULL) ) 
  264.                     DoHelp();
  265.         
  266.                 SetPort( oldPort );
  267.                 continue;
  268.             }
  269.         }
  270.  
  271.         /* We don't want this one.  Drop _this_ event, by its type. */
  272.         
  273.         GetNextEvent( 1 << theEvent.what, &theEvent );
  274.     }
  275. }
  276.  
  277. /* //  */
  278. /* They're trying to change the size of the RAM disk.  Handle the dialog box
  279. as a real dialog now.  The EditText field may be used to directly set the size,
  280. or the size may be dialed in with a scroll bar.  The scroll bar's ActionProc
  281. updates the EditText field.
  282.  
  283. The "Set" button becomes active when the user tries to set the size, i.e., upon
  284. entry to this routine.  It becomes the default button.
  285. */
  286.  
  287. GetNewSize()
  288. /* the current event */
  289. {
  290.     short        type;
  291.     Handle        item;
  292.     Rect        box, setBox;
  293.     PenState    penState;
  294.     GrafPtr        oldPort;
  295.     long        size;
  296.     char        sizePstr[MAXLINE];
  297.     short        itemHit;
  298.     void        ShowNewSize();
  299.     Handle        ramDesc, ramDirSize;
  300.     extern        RamInfo ramInfo;
  301.     long        heapSize, dirSize;
  302.     Ptr            ramStart;
  303.     
  304. /* //  */
  305.     /* Change the appearance of the dialog for setting the size. */
  306.     
  307.     GetPort( &oldPort );
  308.     SetPort( ctlW );
  309.     
  310.     myHideDItem( ctlW, ctlIFile );                /* Remove "Copying". */
  311.     
  312.     GetDItem( ctlW, ctlISet, &type, &item, &setBox );    /* activate "Set" button and... */
  313.     HiliteControl( item, 0 );
  314.     PenMode( notPatCopy );                        /* ...deoutline "Help" button. */
  315.     Outline( ctlW, (short)ctlIOutline );
  316.     
  317.     GetDItem( ctlW, ctlIOutline, &type, &item, &box );
  318.     SetDItem( ctlW, ctlIOutline, type, item, &setBox );
  319.     PenNormal();
  320.     Outline( ctlW, (short)ctlIOutline );
  321.     
  322.     GetDItem( ctlW, ctlIEdit, &type, &item, &box );    /* Disable editText reporting and select text. */
  323.     SetDItem( ctlW, ctlIEdit, type | itemDisable, item, &box );
  324.     SelIText( ctlW, ctlIEdit, 0, 1000 );
  325.     
  326.     GetDItem( ctlW, dlogIScroll, &type, &item, &box );    /* Disable scroll bar reporting. */
  327.     SetDItem( ctlW, dlogIScroll, type | itemDisable, item, &box );
  328.     SetCtlAction( item, ShowNewSize );                /* NOT an actionProc!  Just a place to store an Update proc. */
  329.     SetCRefCon( item, 10 );
  330.     
  331.     SetPort( oldPort );
  332.  
  333. /* //  */
  334.     /* Get the new size. */
  335.     
  336.     do {                        /* Loop lets the user get help. */
  337.         ModalDialog( DialogFilter, &itemHit );
  338.         
  339.         switch( itemHit ) {
  340.         case ctlIHelp:
  341.             DoHelp();
  342.             break;
  343.         case ctlICancel:
  344.             NoRamDisk();
  345.             ExitToShell();
  346.         case ctlIBigDir:
  347.             GetDItem( ctlW, ctlIBigDir, &type, &item, &box );
  348.             SetCtlValue( item, 1-GetCtlValue(item) );
  349.             break;
  350.         }
  351.     } while( itemHit != ctlISet );
  352.     
  353.     GetDItem( ctlW, ctlIEdit, &type, &item, &box );
  354.     GetIText( item, sizePstr );
  355.     StringToNum( sizePstr, &size );
  356.     
  357.     GetDItem( ctlW, ctlIBigDir, &type, &item, &box );
  358.     dirSize = GetCtlValue(item) ? 3 : 1;
  359.     
  360.     if( size < MinDisk/1024 )                    /* Force the size to be reasonable.  If the scroll */
  361.         size = MinDisk/1024;                    /*   bar was used, it set the editText field to a */
  362.     if( size > maxDisk )                        /*   reasonable value already. */
  363.         size = maxDisk;
  364.     
  365.     
  366.     /* Save the new size and make a RAM disk that size. */
  367.     
  368.     NoRamDisk();
  369.     
  370.     ramStart = ramInfo.oldBufPtr - size * 1024;    /* When we run again, make a new RAM */
  371.                                                 /*   disk with the new size. */
  372.  
  373.     ramDesc = GetResource( 'RAMD', 256 );
  374.     *(long *)*ramDesc = heapSize = ramStart - (Ptr)GetZone();
  375.     
  376.     ramDirSize = GetResource( 'RAMD', 257 );
  377.     *(long *)*ramDirSize = dirSize;
  378.     
  379.     ChangedResource( ramDesc );
  380.     ChangedResource( ramDirSize );
  381.     
  382.     if( ! ResError() )
  383.         UpdateResFile( HomeResFile(ramDesc) );    /* in either our file or a control file */
  384.     
  385.     switch( ResError() ) {
  386.     case 0:
  387.         break;
  388.     
  389.     case wPrErr:
  390.     case fLckdErr:
  391.     case vLckdErr:
  392.         Alert( alrtDiskProt, NULL );
  393.         break;
  394.         
  395.     default:
  396.         error("\ptrouble saving ramDesc, resError=^2", (long)ResError());
  397.     }
  398.     
  399.     InitRamDisk( heapSize, ramStart, dirSize );
  400.     ReStartUs();                                /* Never returns. */
  401. }
  402.  
  403. /* //  */
  404. /* Display the Help dialog.  It contains text, a TextEdit field, a scroll
  405. bar, a Continue button, and several radio buttons, one for each chapter.
  406. The TextEdit field scrolls in response to the scroll bar, and its text
  407. cannot be edited. */
  408.  
  409. static TEHandle helpTE;                            /* Used by ShowHelp() also. */
  410.  
  411. DoHelp()
  412. {
  413.     DialogPtr    help;
  414.     short        type;
  415.     Handle        item, version;
  416.     Rect        box, dest;
  417.     static Rect    copyRect = { 46, 10, 78, 273 };
  418.     extern char    copyRight[];
  419.     pascal void    DisplayHelp();
  420.     GrafPtr        oldPort;
  421.     Handle        helpText;
  422.     short        itemHit, currentHelp, oldFont;
  423.     pascal void    TOutline();
  424.     char        str[MAXLINE];
  425.     
  426.     
  427.     help = GetNewDialog( dlogHelp, NULL, -1 );    /* Initially invisible. */
  428.     
  429.     version = GetResource( 'GANr', 0 );
  430.     BlockMove( *version, str, (*version)[0] + 1 );
  431.     BlockMove( copyRight, &str[ str[0]+1 ], copyRight[0] + 1 );
  432.     str[ str[0]+1 ] = '\r';
  433.     str[0] += copyRight[0] + 1;
  434.     
  435.     GetDItem( help, helpIName, &type, &item, &box );
  436.     SetIText( item, str );
  437.     
  438.     GetDItem( help, helpIOutline, &type, &item, &box );    /* userItems */
  439.     SetDItem( help, helpIOutline, type, Outline, &box );
  440.     
  441.     GetDItem( help, helpITOutline, &type, &item, &box );
  442.     SetDItem( help, helpITOutline, type, TOutline, &box );
  443.     
  444.     GetDItem( help, helpIIcon, &type, &item, &box );    /* our icon */
  445.     SetDItem( help, helpIIcon, type, GetResource('ICN#', 128), &box );
  446.     
  447.     GetDItem( help, helpIText, &type, &item, &box );
  448.     SetDItem( help, helpIText, type, DisplayHelp, &box );
  449.     
  450.     GetPort( &oldPort );                        /* Make a TERec in the Dialog box. */
  451.     SetPort( help );
  452.     dest = box;
  453.     InsetRect( &dest, 4, 0 );
  454.     oldFont = thePort->txFont;
  455.     thePort->txFont = 1;                        /* Application font. */
  456.     helpTE = TENew( &dest, &box );
  457.     thePort->txFont = oldFont;
  458.     SetPort( oldPort );
  459.     
  460.     ShowWindow( help );                            /* Show it now, 'cause there'll be a wait. */
  461.     BeginUpdate( help );                        /* Normally done via Update event. */
  462.     DrawDialog( help );
  463.     EndUpdate( help );
  464. /* //  */
  465.     GetDItem( help, helpStarting, &type, &item, &box );    /* choose default text */
  466.     SetCtlValue( item, 1 );
  467.     SetHelp( helpStarting, help );
  468.     currentHelp = helpStarting;
  469.     
  470.     
  471.     while( TRUE ) {
  472.         ModalDialog( DialogFilter, &itemHit );
  473.         
  474.         if( itemHit < helpStarting  ||  itemHit > helpBCS )
  475.             break;
  476.         
  477.         if( itemHit != currentHelp ) {
  478.             GetDItem( help, currentHelp, &type, &item, &box );
  479.             SetCtlValue( item, 0 );
  480.             GetDItem( help, itemHit, &type, &item, &box );
  481.             SetCtlValue( item, 1 );
  482.             
  483.             SetHelp( itemHit, help );
  484.             currentHelp = itemHit;
  485.         }
  486.     }
  487.     
  488.     DisposDialog( help );
  489. }
  490.  
  491.  
  492. SetHelp( helpItem, help )
  493. short            helpItem;
  494. DialogPtr        help;
  495. {
  496.     short        type;
  497.     Handle        item, helpText;
  498.     Rect        box, view, dest;
  499.     void        ShowHelp();
  500.     GrafPtr        oldPort;
  501.     
  502.     
  503.     GetPort( &oldPort );                        /* We're going to put text in it. */
  504.     SetPort( help );
  505.     
  506.     SetCursor( *GetCursor(watchCursor) );
  507.     
  508.     view = dest = (*helpTE)->viewRect;            /* display top line of text */
  509.     InsetRect( &dest, 4, 0 );
  510.     (*helpTE)->destRect = dest;
  511.     EraseRect( &view );
  512.     InvalRect( &view );
  513.     
  514.     helpText = GetResource( 'HELP', 256+helpItem-helpStarting ); /* Get the help text. */
  515.     (*helpTE)->hText = helpText;
  516.     (*helpTE)->teLength = GetHandleSize( helpText );
  517.     TECalText( helpTE );                        /* wait */
  518.     
  519.     TESetSelect( 0, 0, helpTE );                /* at first line */
  520.     GetDItem( help, dlogIScroll, &type, &item, &box );    /* Set up the control. */
  521.     SetCtlMin( item, 1 );
  522.     SetCtlMax( item, (*helpTE)->nLines - 12 );
  523.     SetCtlValue( item, 1 );
  524.     SetCtlAction( item, ShowHelp );                /* NOT an actionProc!  Update proc. */
  525.     SetCRefCon( item, 12 );
  526.     
  527.     InitCursor();
  528.     SetPort( oldPort );
  529. }
  530.  
  531. /* //  */
  532. /* Called by ModalDialog or Help to handle a scroll bar, which must have
  533. the same item number in each dialog.  It also detects Return and Enter so
  534. they still exit the dialog. */
  535.  
  536. pascal Boolean    DialogFilter( theDialog, theEventp, itemHitp )
  537. DialogPtr        theDialog;                        /* --> */
  538. EventRecord        *theEventp;                        /* <-> */
  539. short            *itemHitp;                        /* <-> */
  540. {
  541.     GrafPtr        oldPort;
  542.     Point        thePoint;
  543.     short        whichPart;
  544.     ControlHandle theControl;
  545.     short        type;
  546.     Handle        item;
  547.     Rect        box;
  548.     short        oldValue;
  549.     pascal void    TrackScroll();
  550.     ProcPtr        updateProc;
  551.     
  552.     
  553.     if(     theEventp->what == keyDown            /* So Return will exit the Dialog. */
  554.        &&  (   (theEventp->message & charCodeMask) == '\r'
  555.             || (theEventp->message & charCodeMask) == '\3' ) )
  556.     {
  557.         *itemHitp = 1;
  558.         return( TRUE );
  559.     }
  560.     
  561.     
  562.     if( theEventp->what == mouseDown ) {
  563.         GetPort( &oldPort );
  564.         SetPort( theDialog );
  565.         
  566.         thePoint = theEventp->where;
  567.         GlobalToLocal( &thePoint );
  568.         
  569.         whichPart = FindControl( thePoint, theDialog, &theControl);
  570.         GetDItem( theDialog, dlogIScroll, &type, &item, &box );
  571.         if( (Handle)theControl == item ) {
  572.             
  573.             if( whichPart == inThumb ) {
  574.                 oldValue = GetCtlValue( theControl );
  575.                 TrackControl( theControl, thePoint, NULL );
  576.                 updateProc = GetCtlAction( theControl );
  577.                 (*updateProc)( theDialog, GetCtlValue(theControl), oldValue );
  578.             }
  579.             else TrackControl( theControl, thePoint, TrackScroll );
  580.             
  581.             theEventp->what = nullEvent;        /* We used this event. */
  582.         }
  583.         
  584.         SetPort( oldPort );
  585.     }
  586.     
  587.     return( FALSE );                            /* Don't want ModalDialog to exit. */
  588. }
  589.  
  590. /* //  */
  591. /* Track either scroll bar, performing repetitive actions.  This is called
  592. as a Pascal procedure; its parameters are on the stack. */
  593.  
  594. pascal void        TrackScroll( theControl, partCode )
  595. ControlHandle    theControl;                        /* --> */
  596. short            partCode;                        /* --> */
  597. {
  598.     char        up;
  599.     short        value;
  600.     short        amount;
  601.     ProcPtr        updateProc;
  602.     
  603.     
  604.     up = (partCode == inUpButton) || (partCode == inPageUp);
  605.     value = GetCtlValue( theControl );
  606.     
  607.     if(    partCode
  608.        && (up ? (value > GetCtlMin( theControl ))
  609.               : (value < GetCtlMax( theControl ))) )
  610.     {
  611.         amount = up ? -1 : 1;
  612.         
  613.         if( (partCode == inPageUp) || (partCode == inPageDown) )
  614.             amount *= (int)GetCRefCon( theControl );
  615.         
  616.         SetCtlValue( theControl, value + amount );
  617.         
  618.         updateProc = GetCtlAction( theControl );
  619.         (*updateProc)( (*theControl)->contrlOwner, GetCtlValue(theControl), value );
  620.     }
  621. }
  622.  
  623. /* //  */
  624. /* The Update procs: */
  625.  
  626. /* Show the new size in the editText field.  Current GrafPort is theDialog. */
  627.  
  628. void    ShowNewSize( theDialog, newSize, oldSize )
  629. DialogPtr        theDialog;                        /* --> */
  630. short            newSize, oldSize;                /* --> */
  631. {
  632.     char        sizePstr[32];
  633.     short        type;
  634.     Handle        item;
  635.     Rect        box;
  636.     
  637.     
  638.     NumToString( newSize, sizePstr );
  639.     GetDItem( theDialog, ctlIEdit, &type, &item, &box );
  640.     SetIText( item, sizePstr );
  641.     SelIText( theDialog, ctlIEdit, 0, 1000 );
  642. }
  643.  
  644.  
  645. /* Show the Help text when it is scrolled.  Assumes the TextEdit record. */
  646.  
  647. void    ShowHelp( theDialog, newValue, oldValue )
  648. DialogPtr        theDialog;                        /* --> */
  649. short            newValue, oldValue;                /* --> */
  650. {
  651.     short        linesMoved = newValue - oldValue;
  652.  
  653.  
  654.     TEScroll( 0, -(*helpTE)->lineHeight * linesMoved, helpTE );
  655.     
  656.     BeginUpdate( theDialog );                    /* Normally done via Update event. */
  657.     TEUpdate( &(*helpTE)->viewRect, helpTE );
  658.     EndUpdate( theDialog );
  659. }
  660.  
  661. /* //  */
  662. /* Outline a button in a dialog.  Called by DrawDialog(). */
  663.  
  664. pascal void        Outline( theDialog, theItem )
  665. WindowPtr        theDialog;                        /* --> */
  666. short            theItem;                        /* --> */
  667. {
  668.     short        type;
  669.     Handle        item;
  670.     Rect        box;
  671.     PenState    penState;
  672.     
  673.     
  674.     GetDItem( theDialog, theItem, &type, &item, &box );
  675.     
  676.     GetPenState( &penState );
  677.     
  678.     PenSize( 3, 3 );
  679.     InsetRect( &box, -4, -4 );
  680.     FrameRoundRect( &box, 16, 16 );
  681.     
  682.     SetPenState( &penState );
  683. }
  684.  
  685. /* //  */
  686. /* Outline a TextEdit field in a dialog.  Called by DrawDialog(). */
  687.  
  688. pascal void        TOutline( theDialog, theItem )
  689. WindowPtr        theDialog;                        /* --> */
  690. short            theItem;                        /* --> */
  691. {
  692.     short        type;
  693.     Handle        item;
  694.     Rect        box;
  695.     PenState    penState;
  696.     
  697.     
  698.     GetDItem( theDialog, theItem, &type, &item, &box );
  699.     
  700.     GetPenState( &penState );
  701.     
  702.     PenNormal();
  703.     FrameRect( &box );
  704.     
  705.     SetPenState( &penState );
  706. }
  707.  
  708. /* //  */
  709. /* Display the Help text when DrawDialog() needs to. */
  710.  
  711. pascal void        DisplayHelp( theDialog, theItem )
  712. WindowPtr        theDialog;                        /* --> */
  713. short            theItem;                        /* --> */
  714. {
  715.     TEUpdate( &(*helpTE)->viewRect, helpTE );
  716.     TextFont( 0 );                                /* sigh */
  717. }
  718.  
  719. /* //  */
  720. /* Hide or show a dialog item, the way the new ROMs do (except for editText
  721. items). */
  722.  
  723. myHideDItem( dlog, dItem )
  724. DialogPtr        dlog;
  725. short            dItem;
  726. {
  727.     short        type;
  728.     Handle        item;
  729.     Rect        box;
  730.     GrafPtr        oldPort;
  731.     
  732.     
  733.     if( !dlog )
  734.         return;
  735.     
  736.     GetDItem( dlog, dItem, &type, &item, &box );
  737.     
  738.     if( box.left < 8192 ) {
  739.         GetPort( &oldPort );
  740.         SetPort( dlog );
  741.         EraseRect( &box );
  742.         InvalRect( &box );
  743.         
  744.         SetPort( oldPort );
  745.         box.left += 16384;
  746.         box.right += 16384;
  747.         SetDItem( dlog, dItem, type, item, &box );
  748.     }
  749. }
  750.  
  751.  
  752. myShowDItem( dlog, dItem )
  753. DialogPtr        dlog;
  754. short            dItem;
  755. {
  756.     short        type;
  757.     Handle        item;
  758.     Rect        box;
  759.     GrafPtr        oldPort;
  760.     
  761.     
  762.     if( !dlog )
  763.         return;
  764.     
  765.     GetDItem( dlog, dItem, &type, &item, &box );
  766.     
  767.     if( box.left >= 8192 ) {
  768.         box.left -= 16384;
  769.         box.right -= 16384;
  770.         
  771.         GetPort( &oldPort );
  772.         SetPort( dlog );
  773.         InvalRect( &box );
  774.         SetPort( oldPort );
  775.         
  776.         SetDItem( dlog, dItem, type, item, &box );
  777.     }
  778. }
  779.  
  780.  
  781. GrayBtn( dlog, dItem )
  782. DialogPtr        dlog;
  783. short            dItem;
  784. {
  785.     short        type;
  786.     Handle        item;
  787.     Rect        box;
  788.     
  789.     
  790.     GetDItem( dlog, dItem, &type, &item, &box );
  791.     HiliteControl( item, 255 );
  792.     SetDItem( dlog, dItem, type | itemDisable, item, &box );
  793. }
  794.